/**
 * Copyright (C) 2013 SHANGHAI VOLKSWAGEN, All rights reserved.
 * License version 1.0, a copy of which has been included with this.
 *
 * @File name：com.bwie.community.controller.CommunityController
 * @Create on：2024/3/24
 * @Author：liuchang
 */
package com.bwie.community.controller;

import com.bwie.common.domain.VoObserve;
import com.bwie.common.domain.*;
import com.bwie.common.domain.request.CommunityReq;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.community.service.CommunityService;
import com.bwie.community.service.WebAdd;
import com.bwie.community.util.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>ClassName：CommunityController</p >
 * <p>Description：</p >
 * <p>Author：liuchang</p >
 * <p>Date：2024/3/24</p >
 */
@RestController
public class CommunityController {
    @Autowired
    private CommunityService communityService;
    @Autowired
    private AliOSSUtils aliOSSUtils;
    @Autowired
    private WebAdd webAdd;



    /**
     * <p>查询所有就诊科室</p >
     * @author：liuchang
     * @date：
     * @param：
     * @return：
    */
    @GetMapping("/findAllDept")
    public Result<List<Dept>> findAllDept(){
        List<Dept> list=communityService.findAllDept();
        return Result.success(list);
    }

    /**
     * <p>上传图片</p >
     * @author：liuchang
     * @date：
     * @param：
     * @return：
    */
    @PostMapping("/upload")
     public Result upload(@RequestParam("file")MultipartFile file) throws IOException {
        String url = aliOSSUtils.upload(file);
        return Result.success(url,"图片上传成功");
    }


   /**
    * <p>发布病友圈</p >
    * @author：liuchang
    * @date：
    * @param：
    * @return：
   */
   @PostMapping("/publish")
    public Result publish(@RequestBody@Validated Community community){
       return communityService.publish(community);
   }

   /**
    * <p>es查询病友圈列表</p >
    * @author：liuchang
    * @date：
    * @param：
    * @return：
   */
   @PostMapping("/search")
    public Result<PageResult<DTOCommunity>> search(@RequestBody CommunityReq req){
      return communityService.search(req);
   }
   
   /**
    * <p>根据朋友圈cid查找所有评论的集合</p >
    * @author：liuchang
    * @date：
    * @param： 
    * @return：
   */
   @PostMapping("/findObserveListByCid/{cid}")
   public Result<List<DTOObserve>> findObserveListByCid(@PathVariable("cid") Integer cid){
       return communityService.findObserveListByCid(cid);
   }
   
   /**
    * <p>根据评论id查找用户信息</p >
    * @author：liuchang
    * @date： 
    * @param： 
    * @return：
   */
   @PostMapping("/user/{observeId}")
    public Result<DTOObserve> findUserInfoByObserveId(@PathVariable("observeId") Integer observeId){

       return Result.success(communityService.findUserInfoByObserveId(observeId));
   }
   /**
    * <p>发布评论</p >
    * @author：liuchang
    * @date：
    * @param：
    * @return：
   */
   @PostMapping("/addComment")
    public Result addComment(@RequestBody@Validated VoObserve voObserve){
       return communityService.addComment(voObserve);
   }
   /**
    * <p>我的朋友圈</p >
    * @author：liuchang
    * @date：
    * @param：
    * @return：
   */
   @PostMapping("/findCommunityByUserId")
   public Result<PageResult<Community>> findCommunityByUserId(@RequestBody VoCommunityReq voCommunityReq){
      return communityService.findCommunityByUserId(voCommunityReq);
   }
   /**
    * <p>查询聊天内容</p >
    * @author：liuchang
    * @date：
    * @param：
    * @return：
   */
   @PostMapping("/chatHistoryList/{roomId}")
   public Result<List<ChatHistory>> chatHistoryList(@PathVariable("roomId") String roomId){
       List<ChatHistory> list= webAdd.chatHistoryList(roomId);
       return Result.success(list);
   }

   @PostMapping("/generatePDF")
    public void generatePDF(HttpServletResponse response) throws Exception {
              communityService.generatePDF(response);
   }


}
